# Maintainer: Bruno Pagani <archange@archlinux.org>
# Contributor: AndyRTR <andyrtr@archlinux.org>
# Contributor: Lukas Jirkovsky <l.jirkovsky@gmail.com>

pkgname=vigra
pkgver=1.11.1.r67+g093d57d1
pkgrel=9
pkgdesc="Computer vision library"
arch=(loong64 x86_64)
url="https://ukoethe.github.io/vigra/"
license=(custom:MIT)
depends=(libpng libtiff openexr gcc-libs sh hdf5 fftw)
makedepends=(git cmake boost python-numpy)
checkdepends=(python-nose)
optdepends=('python: for python bindings'
            'boost-libs: for python bindings')
source=(git+https://github.com/ukoethe/vigra#commit=093d57d15c8c237adf1704d96daa6393158ce299
        vigra-python3.10.patch::https://github.com/ukoethe/vigra/commit/e7e656c29083729090dd3fb3ec214a888e0b3e8d.patch
        vigra-numpy1.20.patch::https://github.com/ukoethe/vigra/commit/23ad778502c6436fb6e40ade5e9fd9ddbbad9f35.patch
        vigra-bind-c17.patch::https://github.com/ukoethe/vigra/pull/500.patch
        vigra-openexr3.patch)
sha256sums=('SKIP'
            '18ab55f011458963785442947ed07dd44cb93e8879a8bdda495fb330011621a4'
            '014cff1a7e69415ec15cef6635a7279c429d5bf8df861a4d89193d2209de604d'
            '9c2289f75e6444ad3316b0d46dd7276de10ae81d194cfa10ed84d1e5236aaea0'
            '2572717e39f916c7c463b8f49306b683c5923906be2721f7da181c58b3a2b34b')

pkgver() {
  cd ${pkgname}
  git describe --tags --match "Version-*" | sed 's/^Version-//;s/\([^-]*-g\)/r\1/;s/-/./g;s/\.g/+g/'
}

prepare() {
  cd ${pkgbase}
  patch -p1 < ../vigra-openexr3.patch
  patch -p1 < ../vigra-python3.10.patch
  patch -p1 < ../vigra-numpy1.20.patch
  # https://github.com/ukoethe/vigra/issues/504
  patch -R -p1 < ../vigra-bind-c17.patch
}

build() {
  cmake -B build -S ${pkgbase} \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DPYTHON_EXECUTABLE=/usr/bin/python \
    -DDOCINSTALL=share/doc \
    -DWITH_OPENEXR=true \
    -DWITH_VIGRANUMPY=1
    #-DBUILD_DOCS=OFF \
  make -C build
}

check() {
  # https://github.com/ukoethe/vigra/issues/491
  make -C build -j1 -k check || echo "Tests failed"
}

package() {
  make -C build DESTDIR="${pkgdir}" install
  install -Dm644 ${pkgbase}/LICENSE.txt -t "${pkgdir}"/usr/share/licenses/${pkgname}/
}
